class Solution(object):
    def wiggleMaxLength(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        # remove horizonal
        tmp = []
        last = None
        for num in nums:
            if num!=last:
                tmp.append(num)
            last = num
        nums = tmp

        if len(nums)<=2: return len(nums)

        last = None
        lastDir = None        
        phase = 1
        for num in nums:
            if last!=None:
                dir = num-last
                if lastDir!=None:
                    if dir*lastDir<0:
                        phase+=1
                else:
                    phase+=1
                lastDir=dir
            last=num
        return phase

print(Solution().wiggleMaxLength([1,17,5,10,13,15,10,5,16,8]))
